﻿using Google.Protobuf;
using RazorEngine;
using RazorEngine.Templating;
using System;


namespace SoEasyPlatform
{
    public class TemplateHelper
    {
        public const string EntityKey = "SoEasyPlatform.Entity";
        public static string  GetTemplateValue<T>(string key,string template,T model) 
        {
            try
            {
                var result = Engine.Razor.RunCompile(template, key, model.GetType(), model);
                return result;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                var message = ex.Message;
                if (message.Length > 801)
                {
                    message = message.Substring(801, 700);
                }
                throw new Exception("模版解析出错,"+message);
            }
        }
    }
}
